package com.xsd.juc;

import java.util.concurrent.CountDownLatch;

/**
 * @Description:  倒计时
 * @Author: zhoufuzong
 * @Created: 2021-01-02 16:34:03
 * @Version: 1.1.0
 */

/**
 * run 方法中执行countDown();进行计时
 * 在预期倒计时结束的地方执行 await
 */

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t" + "离开教室");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t" + "班长关教室走人");
    }

    private static void closeDoor() {
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t" + "离开教室");
            }, String.valueOf(i)).start();
        }
        System.out.println(Thread.currentThread().getName() + "\t" + "班长关教室走人");

    }
}